package wish.stages.htmlFilter;

import java.util.Set;
import java.util.Vector;

import org.htmlparser.Attribute;
import org.htmlparser.Node;
import org.htmlparser.NodeFilter;
import org.htmlparser.nodes.TagNode;

public class AttributeContainKeywordsFilter implements NodeFilter {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6068999035888675652L;
	private Set<String> words;

	public AttributeContainKeywordsFilter(Set<String> words){
		this.words = words;
	}
	
	@Override
	public boolean accept(Node node) {

		if (words == null || words.isEmpty())
			return true;
		
		if (node instanceof TagNode){

			TagNode tnode = (TagNode)node;

			Vector<Attribute> atts = tnode.getAttributesEx();

			for (Attribute attribute : atts) {

				if (!attribute.isValued())
					continue;

				for (String word : words) {
					
					if (attribute.getValue().toLowerCase().contains(word.toLowerCase())){

						return true;
					
					}

					
				}
				
			}

			return false;
		}
		else 
			return false;

	}

}
